/*
Copyright (C) 2013-2021 LZE
Prog:Winner Tree 
*/
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MAXN 100000
ll n,m;
ll a[MAXN]={0},tree[MAXN*4]={0};

inline ll lc(ll p){return p<<1;}
inline ll rc(ll p){return p<<1|1;}
void push_up_min(ll p){
	tree[p]=min(tree[lc(p)],tree[rc(p)]);
}
void push_up_max(ll p){
	tree[p]=max(tree[lc(p)],tree[rc(p)]);
}

void build(ll p,ll l,ll r){
	if(l==r){
		tree[p]=a[l];
		return;
	}
	ll mid=(l+r)>>1;
	build(lc(p),l,mid);
	build(rc(p),mid+1,r);
	push_up_max(p);
}
ll query__(ll p,ll l,ll r,ll L,ll R){
	if(R<l||L>r)return -INF;
	if(L<=l&&r<=R)return tree[p];
	ll mid=(l+r)>>1;
	ll sum_left=query__(lc(p),l,mid,L,R);
	ll sum_right=query__(rc(p),mid+1,r,L,R);
	return max(sum_left,sum_right);
}
int main() {
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	build(1,1,n);
	ll x,y;
	for(ll i=1;i<=m;i++){
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",query__(1,1,n,x,y));
	}
	return 0;
}

